<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1">
    <title>注册页面</title>
    <!--    <link rel="stylesheet" href="https://unpkg.com/mint-ui/lib/style.css">-->
    <!--    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>-->
    <!--    <script src="https://unpkg.com/mint-ui/lib/index.js"></script>-->
    <!--    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
    <!--    <script src="https://cdn.bootcss.com/qs/6.5.1/qs.min.js"></script>-->
    <link rel="stylesheet" th:href="@{/formlist/common/style.css}">
    <script th:src="@{/formlist/common/vue.js}"></script>
    <script th:src="@{/formlist/common/index.js}"></script>
    <script th:src="@{/formlist/common/axios.min.js}"></script>
    <script th:src="@{/formlist/common/qs.min.js}"></script>
    <link th:href="@{/formlist/css/reset.css}" rel="stylesheet">
    <link th:href="@{/formlist/css/main.css}" rel="stylesheet">
</head>
<body>
<div id="register" class="registered" style="padding-top: 140px">
    <!--    <div class="username"><mt-field placeholder="请输入需要修改的姓名" v-model="name"></mt-field></div>-->
    <!--    <div class="username"><mt-field placeholder="请输入新密码" v-model="password"></mt-field></div>-->
    <!--    <div class="username"><mt-field placeholder="请再次输入密码" v-model="nPassword"></mt-field></div>-->
    <div><mt-field label="姓名" type="text" placeholder="填写姓名" v-model="name"></mt-field></div>
    <div><mt-field label="原密码" type="password" placeholder="填写原密码" v-model="password" readonly></mt-field></div>
    <div><mt-field label="新密码" type="password" placeholder="填写新密码" v-model="nPassword"></mt-field></div>
    <div><mt-field label="确认密码" type="password" placeholder="确认新密码" v-model="aPassword"></mt-field></div>

    <div class="btn"><mt-button @click.native="handleClick">修改信息</mt-button></div>
    <div class="regist" v-on:click="goBack">返回上一级页面</div>
</div>
<script>
    const qs = Qs;
    const vm = new Vue({
        el: '#register',
        data: {
            message: '请选择>>',
            readOnly: true,
            username: '',
            name: '',
            password: '',
            nPassword: '',
            aPassword: ''
        },
        created: function () {
            this.getMsg();
        },
        methods: {
            getMsg:function (event) {
                axios.post('/system/renyuan/findone', qs.stringify({'userid': localStorage.getItem("userfindid")})).then(res => {
                    this.name = res.data.truename
                    this.password = res.data.password
                    this.nPassword = ''
                    this.aPassword = ''
                });
            },
            handleClick:function (event) {
                if (this.name === '') {
                    this.$toast('请填写姓名！')
                } else if (this.nPassword === '') {
                    this.$toast('请填写新密码！')
                } else if (this.aPassword === '') {
                    this.$toast('请再次填写新密码！')
                } else if(this.nPassword!==this.aPassword) {
                    this.$toast('两次输入的密码不一样，请重新输入！')
                } else {
                    axios.post('/system/renyuan/edit', qs.stringify(
                        {
                            'userid': localStorage.getItem("userfindid"),
                            'truename': this.name,
                            'password': this.nPassword,
                        })
                    ).then(res => {
                        if (res.data.code === 0) {
                            this.$toast('个人信息修改成功！');
                            location.href = '../formlist/login';
                        } else{
                            this.$toast(res.data.msg)
                        }
                    });
                }
            },
            goBack:function (event) {
                window.history.back();
            }
        }

    })
</script>
</body>
</html>